import Vue from 'vue'
import VueRouter from 'vue-router'
//
import { Loading } from 'element-ui';
//
import Main from '../views/Main'
import Login from '../views/Login'
//
import Home from '../views/Home'
//系统管理
import User from '../views/Sys/User'
//
Vue.use(VueRouter)

const routers = [{
        path: '/',
        component: Main,
        children: [{
            path: '/Home',
            name: "/Home",
            component: Home,
            meta: { title: '首页' },
        }, {
            path: '/User',
            name: '/User',
            component: User,
            meta: { title: '用户管理' },
        }]
    },
    { path: '/Login', name: 'Login', component: Login },
    { path: '*', redirect: "/Home" }
];

const vueRouter = new VueRouter({
    routes: routers
});
//let loadingInstance1 = null;
//监听路由
vueRouter.beforeEach((to, from, next) => {
    console.log('路由拦截器', from);
    // loadingInstance1 = Loading.service({
    //     fullscreen: true,
    //     target: '.main-body'
    // });
    //路由拦截器
    if (to.meta.hasOwnProperty('title')) {
        global.$store.commit('main/addOrCheckedTab', {
            title: to.meta.title,
            name: to.name,
            active: true
        });
    }
    next()
});
vueRouter.afterEach(to => {
    // if (loadingInstance1) {
    //     loadingInstance1.close();
    // }
});

export default vueRouter;